<!-- 设计策划 -->
<template>
    <base-breadcrumb>
        <searchData :searchData="searchArr" @search="search"></searchData>
        <a-card>
            <list-table ref="table" size="default" rowKey="id" :columns="columns" :request="loadData" :alert="true"
                :export-config="{
                        use: true,
                        select: '设计策划',
                        all: '设计策划'
                    }"
                        :exportPermission="{ select: 'bm_038_exp_03', all: 'bm_038_exp_03' }"
                      :statistics-config="{ use: true, total, temp }"
                show-size-changer show-quick-jumper showPagination="auto"
                 >
                 <!-- :exportPermission="{select: 'bm_012_edi_02',all: 'bm_012_edi_02'}" -->
                <span slot="operation" slot-scope="text, record">
                    <MoreButton>
                    <a @click="handleUpdate('looks', record)"
                        v-btnPermission="'bm_038_loo_02'">查看</a>
                    <a @click="handleUpdate('edit', record)" v-if="(record.auditStatus == 'DRAFT' || record.auditStatus=='REJECTED')&&hideBuquBtn()"
                        v-btnPermission="'bm_038_edi_01'">编辑</a>
                        <a @click="handleApproveDetail(record)" v-if="record.auditStatus !== 'DRAFT'" v-btn-permission="'bm_038_loo_02'">审批信息</a>
                    </MoreButton>
                </span>
            </list-table>
            <ApprovalDetails
              :title="'审批详情'"
              :business-id="businessId"
              :visible="visibleApprove"
              @cancel="visibleApprove = false"
              @confirm="visibleApprove = false"
      />
        </a-card>
    </base-breadcrumb>
</template>
<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import SelectSubcontractor from '@/components/Select/SelectSubcontractor' // 分包商
import ApprovalDetails from '@/components/approvalDetails'
import { STable } from '@/components'
import listStatus from '@/components/list_status/list_status'
// import { getMeetingList, startMeeting, getSearchList } from '@/api/office/conference'
import { getDesignPlanningList, designPlanningCount } from '@/api/businessAffairs/designPlanning'
import { typeListApproval1 } from '@/utils/util'
const columns = [
    {
        title: '序号',
        width: 80,
        dataIndex: 'index',
        customRender() {
            return arguments[2] + 1
        },
    },

    {
        title: '分公司',
        dataIndex: 'branchComName',
    },
    {
        title: '项目名称',
        dataIndex: 'projectName',
    },
    {
        title: '设计策划目标效益额(不含税)（万元）',
        dataIndex: 'expectedBenefit',
    },
    {
        title: '设计策划目标效益率（%）',
        dataIndex: 'expectedBenefitRate',
    },
    {
        title: '设计策划完成时间',
        dataIndex: 'finishedDate',
    },
    {
        title: '填报人',
        dataIndex: 'informant',
    },
    {
        title: '填报时间',
        dataIndex: 'informantTime',
    },
    {
        title: '状态',
        dataIndex: 'auditStatusName',
    },
    {
        title: '操作',
        dataIndex: 'operation',
        width: '170px',
        scopedSlots: { customRender: 'operation' },
    },
]
const searchArr = [
    {
        name: '所属单位',
        valueKey: 'searchQuery',
        type: OrgTreeSelect,
    },
    {
        name: '设计策划完成时间完成时间',
        value: 'finishedDate',
        type: 'dateRange',
    },
    {
        name: '填报人',
        value: 'informant',
        type: 'input',
    },
    {
        name: '填报时间',
        value: 'informantTime',
        type: 'dateRange',
    },
    {
        name: '状态',
        value: 'auditStatus',
        type: 'select',
        data: typeListApproval1,
    }
]

export default {
    name: 'ac' + Date.now(),
    components: {
        STable,
        listStatus,
        ApprovalDetails
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            countList:{},
            total:{},
            visibleApprove: false,
            temp: () => {
            return (
                <span style="margin-right: 20px">
                 设计策划目标效益总额(不含税)(万元)：<span class="totalNum">{ this.countList.totalBenefit }  </span> 
                 设计策划目标效益平均率(%)：<span class="totalNum">{this.countList.avgBenefitRate }  </span> 
                </span>
            )
          },
            queryParam: {},
            loadData: async (parameter) => {
                this.queryParam = { ...this.queryParam }
                const requestParameters = Object.assign({}, parameter, this.queryParam)
                this.designPlanningCount(requestParameters)
                const  res = await getDesignPlanningList(requestParameters)
              
                res.data.forEach(item => {
                    if(item.auditStatus=='PAST'){
                        item.auditStatusName='审批通过'
                    }else if(item.auditStatus=='SUBMITTED'){
                        item.auditStatusName='审批中'
                    }else if(item.auditStatus=='REJECTED'){
                        item.auditStatusName='审批不通过'
                    }else if(item.auditStatus=='DRAFT'){
                        item.auditStatusName='待提交审批'
                    }
                  if(!item.informant) {
                    item.informantTime = ''
                  }
                });
                console.log(res.data,222)
                return new Promise((resolve, reject) => {
                        resolve(res)
                })
            },
            
        }
    },
    mounted() {
        console.log(11112222)
        // this.getSearchListReq()
    },
    methods: {
        handleApproveDetail(record) {
        this.visibleApprove = true
        this.businessId = record.id
      },
        designPlanningCount(requestParameters){
            designPlanningCount(requestParameters).then(res=>{
            if (res.code === 200) {
                this.countList=res.data
              }
          })
        },
        search(val = {}) {
            this.queryParam = {
                ...val,
                // typeId: 4,

               finishedBeginDate:
                     (val.finishedDate && val.finishedDate.length && val.finishedDate[0].format('YYYY-MM-DD')) || void 0,
               finishedEndDate:
                    (val.finishedDate && val.finishedDate.length && val.finishedDate[1].format('YYYY-MM-DD')) || void 0,
                informantBeginTime:
                    (val.informantTime && val.informantTime.length && val.informantTime[0].format('YYYY-MM-DD')) || void 0,
                informantEndTime:
                    (val.informantTime && val.informantTime.length && val.informantTime[1].format('YYYY-MM-DD')) || void 0,
            }

            console.log("queryParam",this.queryParam)

            this.$refs.table.refresh(true)
        },

        // 处理操作
        async handleUpdate(type, data = {}) {
           
                this.$router.push({
                     name: 'designPlanningEdit',
                     query: {
                        id: data.id || '',
                        pageType: type,
                    },
                 })
        },
    },
}
</script>
